

class BasicInfoController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        
        params.sort = params.sort ? params.sort : "name" 
    	params.order = params.order ? params.order : "ASC"
    		
        [ basicInfoInstanceList: BasicInfo.list( params ), basicInfoInstanceTotal: BasicInfo.count() ]
    }

    def show = {
        def basicInfoInstance = BasicInfo.get( params.id )

        if(!basicInfoInstance) {
            flash.message = "BasicInfo not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ basicInfoInstance : basicInfoInstance ] }
    }

    def delete = {
        def basicInfoInstance = BasicInfo.get( params.id )
        if(basicInfoInstance) {
            try {
                basicInfoInstance.delete()
                flash.message = "BasicInfo ${params.id} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "BasicInfo ${params.id} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "BasicInfo not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def basicInfoInstance = BasicInfo.get( params.id )

        if(!basicInfoInstance) {
            flash.message = "BasicInfo not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ basicInfoInstance : basicInfoInstance ]
        }
    }

    def update = {
        def basicInfoInstance = BasicInfo.get( params.id )
        if(basicInfoInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(basicInfoInstance.version > version) {
                    
                    basicInfoInstance.errors.rejectValue("version", "basicInfo.optimistic.locking.failure", "Another user has updated this BasicInfo while you were editing.")
                    render(view:'edit',model:[basicInfoInstance:basicInfoInstance])
                    return
                }
            }
            basicInfoInstance.properties = params
            if(!basicInfoInstance.hasErrors() && basicInfoInstance.save()) {
                flash.message = "BasicInfo ${params.id} updated"
                redirect(action:show,id:basicInfoInstance.id)
            }
            else {
                render(view:'edit',model:[basicInfoInstance:basicInfoInstance])
            }
        }
        else {
            flash.message = "BasicInfo not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def basicInfoInstance = new BasicInfo()        
        basicInfoInstance.properties = params
        return ['basicInfoInstance':basicInfoInstance]
    }

    def save = {
        def basicInfoInstance = new BasicInfo(params)
        if(!basicInfoInstance.hasErrors() && basicInfoInstance.save()) {
            flash.message = "BasicInfo ${basicInfoInstance.id} created"
            redirect(action:show,id:basicInfoInstance.id)
        }
        else {
            render(view:'create',model:[basicInfoInstance:basicInfoInstance])
        }
    }

}
